package com.ysg.widget.dialog;

import android.annotation.SuppressLint;
import android.content.Context;
import android.widget.ImageView;
import android.widget.TextView;

import com.ysg.R;
import com.ysg.base.BaseDialog;
import com.ysg.utils.YImageUtil;
import com.ysg.utils.YStringUtil;

/**
 * 视频语音价格
 */
public class VideoAudioPriceDialog extends BaseDialog {
    public interface OnPriceListener{
        void onVideoClick();
        void onAudioClick();
    }
    private OnPriceListener listener;
    public void setOnPriceListener(OnPriceListener listener){
        this.listener = listener;
    }

    private String pic, audioPrice, videoPrice;
    public VideoAudioPriceDialog(Context context, String pic, String audioPrice, String videoPrice) {
        super(context);
        this.pic = pic;
        this.audioPrice = audioPrice;
        this.videoPrice = videoPrice;
    }

    private ImageView ivClose,ivAvatar;
    private TextView tvAudio, tvVideo;

    @Override
    public int getLayoutId() {
        return R.layout.dialog_video_audio_price;
    }

    public void initView() {
        ivClose = findViewById(R.id.ivClose);
        ivAvatar = findViewById(R.id.ivAvatar);
        tvAudio = findViewById(R.id.tvAudio);
        tvVideo = findViewById(R.id.tvVideo);
    }


    @Override
    @SuppressLint("StringFormatInvalid")
    public void initData() {
        if (YStringUtil.isNotEmpty(pic)){
            YImageUtil.show(ivAvatar, pic);
        }
        if (YStringUtil.isNotEmpty(audioPrice)){
            String price = String.format(getContext().getResources().getString(R.string.dialog_price_audio), audioPrice);
            tvAudio.setText(price);
        }
        if (YStringUtil.isNotEmpty(videoPrice)){
            String price = String.format(getContext().getResources().getString(R.string.dialog_price_video), videoPrice);
            tvVideo.setText(price);
        }
    }

    @Override
    public void initListener() {
        tvAudio.setOnClickListener((v)->{
            dismiss();
            if (listener != null){
                listener.onAudioClick();
            }
        });
        tvVideo.setOnClickListener((v)->{
            dismiss();
            if (listener != null){
                listener.onVideoClick();
            }
        });
        ivClose.setOnClickListener((v)->{
            dismiss();
        });
    }


}
